﻿
function getTop(height){
	var windowheight=window.innerHeight;
	return (windowheight-height)/2;
}
function getLeft(width){
	var windowwidth=window.innerWidth;
	return (windowwidth-width)/2;
}
/*---------------------------------------------------------------------*/

function myFriendsAll(){
	
	document.getElementById("myDesignTable").style.display="none";
	document.getElementById("myOrderTable").style.display="none";
	$(".shoppingCar_subtitle").hide();
			// at id=friend_content_right's div add the friend and privatecenter label
			/*-------------------------------THE TOP CONTENT BEGIN-----------------------------------*/
			$("#friend_content_right").html("");//clean all the friend_content_right content
			$("#friend_content_right").append("<div class='myfriend_friendactivity_content_right_childtitle'></div>");
			$(".myfriend_friendactivity_content_right_childtitle").append("<div class='myfriend_friendactivity_content_right_childtitle_left'></div>");
			$(".myfriend_friendactivity_content_right_childtitle_left").append("<div style='width:153px; height:23px; float:left; padding-top:3px; text-align:left;'><a href='javascript:void(0);' onclick='showfriendschange()'>好友动态</a>(<span id='osccount'></span>条)</div>");
			
			$(".myfriend_friendactivity_content_right_childtitle").append("<div class='myfriend_friendactivity_content_right_childtitle_right'></div>");
			$(".myfriend_friendactivity_content_right_childtitle_right").append("<div style='width:153px; height:23px; padding-top:3px;'><a href='javascript:void(0);' onclick='showtalkenchother()'>私聊中心</a>(<span id='privatecount'></span>条)</div>");
			/*--------------------------------THE ORDER,SHARE,COMMENT CONTENT ------------------------*/
			$("#friend_content_right").append("<div id='osc_all_content'></div>");
			$("#friend_content_right").append("<div id='privatetalkcentre' style='display:block;'></div>");
			$("#osc_all_content").append("<div id='osc'></div><div class='holder2'></div>");//THIS DIV INCLUDE THREE CONTENT 
			
			//TURN TO ACTION AND READ THE CONTENTS OF ORDER AND SHARE AND COMMENT
			
				$.getJSON('MyFriendsTrendsActionByAJAX?time='+Math.random(10),function(data){
					var the_oscCount=data.list.length+data.listShare.length+data.customlist.length+data.listShare.length+data.commentcust.length+data.partshareincustom.length+data.partshareinorder.length+data.commentorder.length;
					$("#osccount").html(the_oscCount);
					var privateCount=data.fromNames.length;
					$("#privatecount").html(privateCount);
					$.each(data.list,function(index,value){
							var face=value.userFace;
							var orderId=value.orderId;
							var friendName=value.userName;
							var time=value.orderTime;
							var customPic=value.customPic;
							$("#osc").append("<div class='myfriend-friendactivity_child'>"+
							"<div class='myfriend-friendactivity_child_userimg'>"+
							"<a href='getFriendOwnMessageAction?uname="+friendName+"'><img src='"+face+"'/></a></div>"+
							"<div class='myfriend-friendactivity_child_username'>"+
							"<a href='getFriendOwnMessageAction?uname="+friendName+"'>"+friendName+"</a></div>"+
							"<div class='myfriend-friendactivity_child_stylecando'>"+
							"<a href='#'>定制</a></div>"+
							"<div class='myfriend-friendactivity_child_production_img'>"+
							//"<a href='javascript:void(0);' onclick='ShowMoreComment("+orderId+")''><img src='"+customPic+"'/></a></div>"+
							"<img src='"+customPic+"'/></div>"+
							"<div class='myfriend-friendactivity_child_time'>"+
							newData(time)+"</div>"+"</div>");
					});
					$.each(data.customlist,function(index,value){
						var orderId=value.orderId;
						var face=value.userFace;
						var friendName=value.userName;
						var time=value.orderTime;
						var customPic=value.customPic;
						$("#osc").append("<div class='myfriend-friendactivity_child'>"+
								"<div class='myfriend-friendactivity_child_userimg'>"+
								"<a href='getFriendOwnMessageAction?uname="+friendName+"'><img src='"+face+"'/></a></div>"+
								"<div class='myfriend-friendactivity_child_username'>"+
								"<a href='getFriendOwnMessageAction?uname="+friendName+"'>"+friendName+"</a></div>"+
								"<div class='myfriend-friendactivity_child_stylecando'>"+
								"<a href='#'>定制</a></div>"+
								"<div class='myfriend-friendactivity_child_production_img'>"+
								//"<a href='javascript:void(0);' onclick='ShowMoreComment("+orderId+")''><img src='"+customPic+"'/></a></div>"+
								"<img src='"+customPic+"'/></div>"+
								"<div class='myfriend-friendactivity_child_time'>"+
								newData(time)+"</div>"+"</div>");
					});
					$.each(data.listShare,function(index,value){
						var orderId=value.orderId;
						var face=value.userFace;
						var friendName=value.userName;
						var time=value.orderTime;
						var customPic=value.customPic;
						$("#osc").append("<div class='myfriend-friendactivity_child'>"+
						"<div class='myfriend-friendactivity_child_userimg'>"+
						"<a href='getFriendOwnMessageAction?uname="+friendName+"'><img src='"+face+"'/></a></div>"+
						"<div class='myfriend-friendactivity_child_username'>"+
						"<a href='getFriendOwnMessageAction?uname="+friendName+"'>"+friendName+"</a></div>"+
						"<div class='myfriend-friendactivity_child_stylecando'>"+
						"<a href='#'>分享</a></div>"+
						"<div class='myfriend-friendactivity_child_production_img'>"+
						//"<a href='javascript:void(0);' onclick='ShowMoreComment("+orderId+")'><img src='"+customPic+"'/></a></div>"+
						"<img src='"+customPic+"'/></div>"+
						"<div class='myfriend-friendactivity_child_time'>"+
						newData(time)+"</div>"+"</div>");
				});
					$.each(data.customShare,function(index,value){
						var orderId=value.orderId;
						var face=value.userFace;
						var friendName=value.userName;
						var time=value.orderTime;
						var customPic=value.customPic;
						$("#osc").append("<div class='myfriend-friendactivity_child'>"+
						"<div class='myfriend-friendactivity_child_userimg'>"+
						"<a href='getFriendOwnMessageAction?uname="+friendName+"'><img src='"+face+"'/></a></div>"+
						"<div class='myfriend-friendactivity_child_username'>"+
						"<a href='getFriendOwnMessageAction?uname="+friendName+"'>"+friendName+"</a></div>"+
						"<div class='myfriend-friendactivity_child_stylecando'>"+
						"<a href='#'>分享</a></div>"+
						"<div class='myfriend-friendactivity_child_production_img'>"+
						//"<a href='javascript:void(0);' onclick='ShowMoreComment("+orderId+")'><img src='"+customPic+"'/></a></div>"+
						"<img src='"+customPic+"'/></div>"+
						"<div class='myfriend-friendactivity_child_time'>"+
						newData(time)+"</div>"+"</div>");
					});
					$.each(data.partshareinorder,function(index,value){
						var orderId=value.orderId;
						var face=value.userFace;
						var friendName=value.userName;
						var time=value.orderTime;
						var customPic=value.customPic;
						$("#osc").append("<div class='myfriend-friendactivity_child'>"+
						"<div class='myfriend-friendactivity_child_userimg'>"+
						"<a href='getFriendOwnMessageAction?uname="+friendName+"'><img src='"+face+"'/></a></div>"+
						"<div class='myfriend-friendactivity_child_username'>"+
						"<a href='getFriendOwnMessageAction?uname="+friendName+"'>"+friendName+"</a></div>"+
						"<div class='myfriend-friendactivity_child_stylecando'>"+
						"<a href='#'>分享</a></div>"+
						"<div class='myfriend-friendactivity_child_production_img'>"+
						//"<a href='javascript:void(0);' onclick='ShowMoreComment("+orderId+")'><img src='"+customPic+"'/></a></div>"+
						"<img src='"+customPic+"'/></div>"+
						"<div class='myfriend-friendactivity_child_time'>"+
						newData(time)+"</div>"+"</div>");
					});
					$.each(data.partshareincustom,function(index,value){
						var orderId=value.orderId;
						var face=value.userFace;
						var friendName=value.userName;
						var time=value.orderTime;
						var customPic=value.customPic;
						$("#osc").append("<div class='myfriend-friendactivity_child'>"+
						"<div class='myfriend-friendactivity_child_userimg'>"+
						"<a href='getFriendOwnMessageAction?uname="+friendName+"'><img src='"+face+"'/></a></div>"+
						"<div class='myfriend-friendactivity_child_username'>"+
						"<a href='getFriendOwnMessageAction?uname="+friendName+"'>"+friendName+"</a></div>"+
						"<div class='myfriend-friendactivity_child_stylecando'>"+
						"<a href='#'>分享</a></div>"+
						"<div class='myfriend-friendactivity_child_production_img'>"+
						//"<a href='javascript:void(0);' onclick='ShowMoreComment("+orderId+")'><img src='"+customPic+"'/></a></div>"+
						"<img src='"+customPic+"'/></div>"+
						"<div class='myfriend-friendactivity_child_time'>"+
						newData(time)+"</div>"+"</div>");
					});
					
					$.each(data.commentcust,function(index,value){
						var face=value.userFace;
						var friendName=value.userName;
						var customPic=value.customPic;
						var time=value.commentTime;
						$("#osc").append("<div class='myfriend-friendactivity_child'>"+
						"<div class='myfriend-friendactivity_child_userimg'>"+
						"<a href='getFriendOwnMessageAction?uname="+friendName+"'><img src='"+face+"'/></a></div>"+
						"<div class='myfriend-friendactivity_child_username'>"+
						"<a href='getFriendOwnMessageAction?uname="+friendName+"'>"+friendName+"</a></div>"+
						"<div class='myfriend-friendactivity_child_stylecando'>"+
						"<a href='#'>评论</a></div>"+
						"<div class='myfriend-friendactivity_child_production_img'>"+
						//"<a href='getFriendOwnMessageAction?uname="+friendName+"'><img src='"+customPic+"'/></a></div>"+
						"<img src='"+customPic+"'/></div>"+
						"<div class='myfriend-friendactivity_child_time'>"+
						newData(time)+"</div>"+"</div>");
				});
					$.each(data.commentorder,function(index,value){
						var face=value.userFace;
						var friendName=value.userName;
						var customPic=value.customPic;
						var time=value.commentTime;
						$("#osc").append("<div class='myfriend-friendactivity_child'>"+
						"<div class='myfriend-friendactivity_child_userimg'>"+
						"<a href='getFriendOwnMessageAction?uname="+friendName+"'><img src='"+face+"'/></a></div>"+
						"<div class='myfriend-friendactivity_child_username'>"+
						"<a href='getFriendOwnMessageAction?uname="+friendName+"'>"+friendName+"</a></div>"+
						"<div class='myfriend-friendactivity_child_stylecando'>"+
						"<a href='#'>评论</a></div>"+
						"<div class='myfriend-friendactivity_child_production_img'>"+
						//"<a href='getFriendOwnMessageAction?uname="+friendName+"'><img src='"+customPic+"'/></a></div>"+
						"<img src='"+customPic+"'/></div>"+
						"<div class='myfriend-friendactivity_child_time'>"+
						newData(time)+"</div>"+"</div>");
				});
					if(data.list.length+data.listShare.length+data.customlist.length+data.listShare.length+data.commentcust.length+data.partshareincustom.length+data.partshareinorder.length+data.commentorder.length>0){
						DoJpages();
					}else{
						$("#osc").append("暂无任何好友动态");
					}
					
					//GET TNE ORDER SHARE  COMMENT ALL COUNT
					
					$("#privatetalkcentre").append("<div id='register-form'></div>");
					$("#privatetalkcentre").append("<div id='report_success'></div>");
					$("#privatetalkcentre").append("<div id='alleachtalk'></div><div class='holder4'></div>");
					$.each(data.fromNames,function(index1,value1){
						var talkcount=0;
						$("#alleachtalk").append("<div id='"+value1+"'</div>");
						$("#"+value1).append("<div id='"+value1+"each_private_content_top'></div>");
						$("#"+value1).append("<div id='"+value1+"each_private_content_center' style='display:none;'></div>");
						$("#"+value1).append("<div id='"+value1+"each_private_content_down'></div><br/>");
						$.each(data.messages,function(index2,value2){
							if(value1==value2.fromName){
								talkcount++;
								if(value2.messageContent.length>10){
									//<span style='size: 2px; cursor: pointer;' onclick='showAllprivatetalk(\""+value2.messageId+"\")' >▼</span>
									$("#"+value1+"each_private_content_top").html("<span style='float:left;'><font color='#99ccff'>"+value2.fromName+":</font></span><span style='float:center;'>"+value2.messageContent.substring(0,10)+"...</span><span style='float:right;'>"+value2.messageTime+"</span><br/>");
									$("#"+value1+"each_private_content_center").append("<span style='float:left;'><font color='#99ccff'>"+value2.fromName+":</font></span><span style='float:center;'>"+value2.messageContent.substring(0,10)+"...<span style='size: 2px; cursor: pointer;' onclick='showAllprivatetalk(\""+value2.messageId+"\")' >▼</span></span><span style='float:right;'>"+value2.messageTime+"</span><br/>");
									$("#"+value1+"each_private_content_center").append("<span style='float:center;display:none;' id='"+value2.messageId+"'>"+value2.messageContent.substring(10,value2.messageContent.length)+"<span onclick='hideAllprivatetalk(\""+value2.messageId+"\")' style='cursor: pointer;'>▲</span></span><br/>");
								}else{
									$("#"+value1+"each_private_content_top").html("<span style='float:left;'><font color='#99ccff'>"+value2.fromName+":</font></span><span style='float:center;'>"+value2.messageContent+"</span><span style='float:right;'>"+value2.messageTime+"</span><br/>");
									$("#"+value1+"each_private_content_center").append("<span style='float:left;'><font color='#99ccff'>"+value2.fromName+":</font></span><span style='float:center;'>"+value2.messageContent+"</span><span style='float:right;'>"+value2.messageTime+"</span><br/>");
								}
							}
						});
						$("#"+value1+"each_private_content_center").append("<span onclick='hideAllprivatetalk(\""+value1+"each_private_content_center\")' style='cursor: pointer;'>▲</span>");
						$("#"+value1+"each_private_content_down").html("<span style='float:right'><a  href='javascript:void(0);' onclick='slidedown(\""+value1+"each_private_content_center\")'>共"+talkcount+"条私聊</a>|<a href='javascript:void(0);' onclick='openDialog2(\""+value1+"\")'>继续聊</a></span><br/>");
					});
					if(data.messages.length==0){
						$("#alleachtalk").html("亲，暂时没有数据哦");
					}else{
						DoPrivateJpages();
					}
					$("#privatetalkcentre").fadeOut(0);
				});
			}
/*---------------------------------------------------------------------*/
function newData(d){
	var i=d.indexOf("T");
	var str=" "+d.substr(0,i)+" "+d.substr(i+1,d.length);
	return str;
	
}
/*---------------------------------------------------------------------*/
		function DoPrivateJpages(){
			$("div.holder4").jPages({
			    containerID :"alleachtalk",
				first: '首页',
				last: '尾页',
				previous: '上页',
				next: '下页',
			    perPage:8,
				/*animation: 'wobble',*/
				callback: function( pages, items ){
					items.showing.find("img").trigger("turnPage");
					items.oncoming.find("img").trigger("turnPage");
				}
			});}
/*---------------------------------------------------------------------*/
		function slidedown(id){
			$("#"+id).slideDown(1000);
		}
/*---------------------------------------------------------------------*/
		function openDialog2(customName){
			var content="";
			 $("#register-form").dialog({
	        	  resizable:false,
	        	  show: "slide",
	        	  autoOpen:true,
	              module : true,
	              width:600,
	              height:450,
	              position:[getLeft(600),getTop(450)],//定位
	              title: "找他私聊下",
	              open:function(){
	            	  $("#register-form").append(privatetalkstr_friend).fadeIn();
	            	  $("#toName").val(customName);
	            	setTimeout("initSWFUpload3()",1000);
	              },
	              close: function(event, ui){
	            	  $("#messagContent").val("");
	            	  $("#register-form").html("");
	              },
	              buttons:{
	            	  '提交' :function(){
	            		  content= $("#messagContent").val();
	            		  if(content==null||content==""){
	            			  alert("您还没输入信息");
	            		  }else{
	            			  if(upload3.getStats().files_queued !== 0){
		            			  sendswf3();
		            		  }else if(upload3.getStats().files_queued === 0){
		            				alert("file is null");
		            			  $.post('SwfSuccessToDateBase',{'toName':$("#toName").val(),'filesName':"",'messageContent':$("#messagContent").val()},function(data){
		            					if(data=="true"){
		            						$("#message").html("您的私聊已经发到").dialog({
		            							autoOpen:true,
		            							width:300,
		            							height:180,
		            							position:[getLeft(300),getTop(180)],
		            							buttons:{
		            								确定:function(){
		            									$(this).dialog("close");
		            									$("#register-form").dialog("close");
		            								}
		            							}
		            						});
		            						
		            					}else{
		            							alert("发送失败");
		            							$("#register-form").dialog("close");
		            					}
		            				});
		            		  }
	            		  }
	            		  
	            	  },
	            	  '取消':function(){
	            		  $(this).dialog('close');
	            	  }
	              },
	        });
		}
/*---------------------------------------------------------------------*/
		function hideAllprivatetalk(id)
		{
			$("#"+id).slideUp(1000);
		}
/*---------------------------------------------------------------------*/
		function showAllprivatetalk(id)
		{
			$("#"+id).slideDown(1000);
		}
/*---------------------------------------------------------------------*/
		function DoJpages(){
			$("div.holder2").jPages({
			    containerID :"osc",
				first: '首页',
				last: '尾页',
				previous: '上页',
				next: '下页',
			    perPage:6,
				/*animation: 'wobble',*/
				callback: function( pages, items ){
					items.showing.find("img").trigger("turnPage");
					items.oncoming.find("img").trigger("turnPage");
				}
			});
		}
/*---------------------------------------------------------------------*/
		function  showtalkenchother(){ 
			$("#osc_all_content").hide();
			$("#privatetalkcentre").show();
		}
/*---------------------------------------------------------------------*/
		function  showfriendschange(){
			$("#moneyall").addClass('myfriend_friendactivity_content_right_select_mymoney');
			$("#friendall").addClass('myfriend_friendactivity_content_right_select_myfriend');
			$("#osc_all_content").show();
			//$("#alleachtalk").html("");
			$("#privatetalkcentre").hide();
		} 
/*---------------------------------------------------------------------*/
		var privatetalkstr_friend="<div id='privatemessage' align='center' style='background-color:#FFFAFO;'>"+
		"<table align='center'>"+
			"<tr>"+
				"<td>"+"发给aaa:"+"</td>"+
				"<td>"+
					"<input type='text' name='toName' id='toName' readonly='readonly'/>"+
				"</td>"+
			"</tr>"+
			"<tr>"+
					"<td>"+"内容:"+"</td>"+
					"<td>"+
						"<textarea rows='6' cols='70' name='messagContent' id='messagContent'></textarea>"+
					"</td>"+
			"</tr>"+
		"</table>"+
		"<div align='center'>"+
			"<table>"+
				  "<tr>"+
						"<td>"+
							"<div align='right'>"+
								"<span id='spanButtonPlaceholder3'></span>"+
							"</div>"+
						"</td>"+
						"<td>"+
							"<div align='left'>"+
								"<input id='btnCancel3' type='button' value='取消上传的文件' onclick='cancelQueue(upload3)' disabled='disabled' style='margin-left: 2px; height: 22px; font-size: 8pt;' />"+
							"</div>"+
						"</td>"+
				  "</tr>"+
			      "<tr>"+
					"<td colspan='2' align='center'>"+
						"<div class='fieldset flash' id='fsUploadProgress3'>"+
							"<span class='legend'>文件上传</span>"+
						"</div>"+
					"</td>"+
		      "</tr>"+
			"</table>"+
		"</div>"+
		"</div>";
		
		
	/*---------------------------------------------------------------------*/
		var upload3;
		function sendswf3(){
			 upload3.startUpload();
		}
		function initSWFUpload3() {
			var settings = {
				flash_url : "swfupload/swfupload.swf",
				 upload_url: "PrivateTalkSWFUploadAction",
				 post_params: {"toName" :$("#toName").val()},
				file_size_limit : "100 MB",
				file_post_name: "file",
				file_types : "*.txt;*.gif",
				file_types_description : "txt模式和JPG",
				file_upload_limit : 100,
				file_queue_limit : 0,
				custom_settings : {
					progressTarget : "fsUploadProgress2",
					cancelButtonId : "btnCancel2"
				},
				debug: false,

				//button_image_url: "img/51.png",
				button_width: "80",
				button_height: "29",
				button_placeholder_id: "spanButtonPlaceholder3",
				button_text: '<span class="theFont">选取文件</span>',
				button_text_style: ".theFont { font-size: 16; }",
				button_text_left_padding: 12,
				button_text_top_padding: 3,
				
				// The event handler functions are defined in handlers.js
				file_dialog_start_handler : fileDialogStart_privateTalk,
				file_queued_handler : fileQueued_privateTalk,
				file_queue_error_handler : fileQueueError_privateTalk,
				file_dialog_complete_handler : fileDialogComplete_privateTalk,
				upload_start_handler : uploadStart_privateTalk,
				upload_progress_handler : uploadProgress_privateTalk,
				upload_error_handler : uploadError_privateTalk,
				upload_success_handler : uploadSuccess_privateTalk,
			    upload_complete_handler : uploadComplete_privateTalk,
			};
			upload3 = new SWFUpload(settings);
		 };
		 function ShowMoreComment(Customid){
				//alert(Customid);
				window.open("ShareInfo?_id="+Customid);
			}